package com.ijpay.controller;

import com.ijpay.model.App;
import com.ijpay.service.AppService;
import com.jfinal.core.Controller;
import com.jfinal.kit.LogKit;
import com.jpay.vo.AjaxResult;

public class IJPayController extends Controller {

	AjaxResult ajax = new AjaxResult();

	AppService appService = new AppService();

	public void toPay() {
		String appId = getPara("appId");
		App app = appService.getAppByAppId(appId);
		if (app == null) {
			renderText("应用不存在");
			return;
		}
		if (app.getStatus() == 0) {
			renderText("应用状态不可用");
			return;
		}
		String userAgent = getRequest().getHeader("User-Agent");
		LogKit.info("toPay userAgent>" + userAgent);
		int payType = 0;
		String agent = userAgent.toLowerCase();
		if (agent.indexOf("micromessenger") > 0) {
			LogKit.info("toPay view wxpay...");
			payType = 1;
		} else if (agent.indexOf("alipayclient") > 0) {
			LogKit.info("toPay view alipay...");
			payType = 2;
		}
		LogKit.info("支付方式为：" + payType);
		// 可以在前端展示app信息
		setAttr("app", app);
		setAttr("payType", 2);
		render("pay.html");
	}
}
